#include "../game_server.cpp"
#include "../room.cpp"
#include "../user.cpp"
#include "../protocol_dist.hpp"
#include "ws_websocket.hpp"
#include <iostream>

using namespace std;
FASTDO_API void ActionMain(ProtocolC2SGetRoom *msg, pWsReqCtx ctx, GameServer &game)
{
    User *user = nullptr;
    for (auto iter = game.userList.begin(); iter != game.userList.end(); iter++)
    {
        if ((*iter)->isYourCtx(ctx))
        {
            user = iter->get();
        }
    }

    auto room = game.getRoom(msg->id);
    ProtocolS2CGetRoom rtn;
    if (room)
    {
        rtn.ok = true;
        rtn.room = room->toProtocol();
    }
    ctx->send(ws::OpCode::dataText, false, rtn.toMixed().json());
}